package cn.com.lsy.product.lepao.validators.impl;

import cn.com.lsy.product.lepao.validators.IPhoneValidators;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IPhoneValidatorsClass implements ConstraintValidator<IPhoneValidators, Object> {
	
	@Override
	public void initialize(IPhoneValidators girlFormValidator) {

	}

	@Override
	public boolean isValid(Object value, ConstraintValidatorContext arg1) {
		if (check((String) value)) {
			return true;
		}
		return false;
	}

	public boolean check(String value) {

		String regex = "^1[3|4|5|7|8|9][0-9]\\d{4,8}$";
		if (value.length() != 11) {
			return false;
		} else {
			Pattern p = Pattern.compile(regex);
			Matcher m = p.matcher(value);
			boolean isMatch = m.matches();
			if (isMatch) {
				return true;
			} else {
				return false;
			}
		}
	}

}
